/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Pembelian.java
 *
 * Created on 20 Feb 11, 22:40:09
 */

package Transaksi;

import java.awt.event.FocusEvent;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Locale;
import javax.print.attribute.standard.DateTimeAtCreation;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import koneksi.koneksi;
import java.util.Date;

/**
 *
 * @author UserXP
 */
public class Pembelian extends javax.swing.JInternalFrame {

    private Date                tglsekarang         = new Date();
    private SimpleDateFormat    smpdtfmt            = new SimpleDateFormat
                                                      ("dd MMM yyyy", Locale.getDefault());
    private SimpleDateFormat    smpdtfmt2           = new SimpleDateFormat
                                                      ("yyyy-mm-dd", Locale.getDefault());
    private String              Tanggal             = smpdtfmt.format(tglsekarang);


    private DefaultTableModel dtm;
    private JTable tableDialogSuplier;
    private JTable tableDialogBarang;
    private JTable tableBeli;
    private JTable tabelCari=null;
    koneksi config=new koneksi();

    /** Creates new form Pembelian */
    private Object[][] getDataSuplierDialog(){
        Object[][] data1=null;
        try{
            koneksi config=new koneksi();
            config.BuatKoneksiDB();
            Statement st=config.getConnection().createStatement();
            ResultSet rs=st.executeQuery(
                    "Select * from suplier where nama_suplier like ('%" +
                    ""+txtCari_suplier.getText()+"%') order by kode_suplier");
            rs.last();
            int rowCount=rs.getRow();
            rs.beforeFirst();
            data1=new Object[rowCount][5];
            int no=-1;
            while(rs.next()){
                no=no+1;
                data1[no][0]=rs.getString(1);
                data1[no][1]=rs.getString(2);
                data1[no][2]=rs.getString(3);
                data1[no][3]=rs.getString(4);
                data1[no][4]=rs.getString(5);
            }
            st.close();
            rs.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, "Koneksi SQL Gagal");
            e.printStackTrace();
        }
        return data1;
    }
    public void tampilTabelSuplierDialog(){
        String[] columnNames={"Kode Suplier","Nama","alamat","Telephone","Kontak Person"};
        tableDialogSuplier=new JTable();
        tableDialogSuplier.setModel(new DefaultTableModel(getDataSuplierDialog(),columnNames){
                boolean[] canEdit = new boolean[]{
                    false, false, false, false, false
                };
            @Override
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit[columnIndex];
                }
        });
        jScrollPane1.setViewportView(tableDialogSuplier);

    }
    private Object[][] getDataBarangDialog(){
        Object[][] data1=null;
        try{
            koneksi config=new koneksi();
            config.BuatKoneksiDB();
            Statement st=config.getConnection().createStatement();
            ResultSet rs=st.executeQuery(
                    "Select * from barang where nama_Barang like " +
                    "('%"+txtCari_Barang.getText()+"%') order by kode_barang");
            rs.last();
            int rowCount=rs.getRow();
            rs.beforeFirst();
            data1=new Object[rowCount][5];
            int no=-1;
            while(rs.next()){
                no=no+1;
                data1[no][0]=rs.getString(1);
                data1[no][1]=rs.getString(2);
                data1[no][2]=rs.getString(3);
                data1[no][3]=rs.getString(4);
                data1[no][4]=rs.getString(5);
            }
            st.close();
            rs.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, "Koneksi SQL Gagal");
            e.printStackTrace();
        }
        return data1;
    }
    public void tampilTabelBarangDialog(){
        String[] columnNames={"Kode Barang","Nama","Golongan","Harga Beli","Stok Ready"};
        tableDialogBarang=new JTable();
        tableDialogBarang.setModel(new DefaultTableModel(getDataBarangDialog(),columnNames){
                boolean[] canEdit = new boolean[]{
                    false, false, false, false, false
                };
            @Override
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit[columnIndex];
                }
        });
        jScrollPane2.setViewportView(tableDialogBarang);

    }
    private Object[][] getDataBeli(){
        Object[][] data1=null;
        try{
            koneksi config=new koneksi();
            config.BuatKoneksiDB();
            Statement st=config.getConnection().createStatement();
            ResultSet rs=st.executeQuery(
                    "Select * from pembelian_detil where kode_pembelian=" +
                    "'"+txtId_pembelian.getText()+"'");
            rs.last();
            int rowCount=rs.getRow();
            rs.beforeFirst();
            data1=new Object[rowCount][5];
            int no=-1;
            while(rs.next()){
                no=no+1;
                data1[no][0]=rs.getString(1);
                data1[no][1]=rs.getString(2);
                data1[no][2]=rs.getString(3);
                data1[no][3]=rs.getString(4);
                data1[no][4]=rs.getString(5);
            }
            st.close();
            rs.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, "Koneksi SQL Gagal");
            e.printStackTrace();
        }
        return data1;
    }
    public void tampilTabelBeli(){
        String[] columnNames={"Id","Kode Pembelian","Kode Barang","Jumlah","Sub Total"};
        tableBeli=new JTable();
        tableBeli.setModel(new DefaultTableModel(getDataBeli(),columnNames){
                boolean[] canEdit = new boolean[]{
                    false, false, false, false
                };
            @Override
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit[columnIndex];
                }
        });
        jScrollPane3.setViewportView(tableBeli);

    }
    public void tampilIdPembelian(){
        koneksi config=new koneksi();
        config.BuatKoneksiDB();
        
        try{
            String sql="select max(kode_pembelian) as maxcode from pembelian_detil";
            Statement st=config.getConnection().createStatement();
            ResultSet rs=st.executeQuery(sql);
            if(rs.next()){
                int No_Faktur=rs.getInt("maxcode");
                No_Faktur=No_Faktur+1;
                String No_Fakturku=Integer.toString(No_Faktur);
                txtId_pembelian.setText(No_Fakturku);
            }else{
                txtId_pembelian.setText("2");
            }
            rs.close();
            st.close();
        }catch(Exception e){

        }
    }
    private void loadCariSuplierDialog(){
        CariDialogSuplier.setSize(500, 500);
        CariDialogSuplier.setVisible(true);
        CariDialogSuplier.setLocationRelativeTo(this);
        tampilTabelSuplierDialog();
    }
    private void LoadCariSuplier(){
         if(txtKode_suplier.getText().equals("")){
                loadCariSuplierDialog();
                CariDialogSuplier.setTitle("Cari Suplier");
            }else{
                try{
                koneksi config=new koneksi();
                config.BuatKoneksiDB();
                Statement st=config.getConnection().createStatement();
                ResultSet rs=st.executeQuery("Select nama_suplier from suplier where" +
                        " kode_suplier='"+txtKode_suplier.getText()+"'");
                if(rs.next()){
                    txtNama_suplier.setText(rs.getString(1));
                    txtKode_barang.setEnabled(true);
                    txtKode_barang.requestFocus();
                }else{
                    JOptionPane.showMessageDialog(this, "Kode Suplier Belum Tersedia");
                    CariDialogSuplier.setVisible(false);
                    txtKode_suplier.setText("");
                    txtKode_suplier.requestFocus();
                }
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
    }
    private void loadCariBarangDialog(){
        CariDialogBarang.setSize(500, 500);
        CariDialogBarang.setVisible(true);
        CariDialogBarang.setLocationRelativeTo(this);
        tampilTabelBarangDialog();
    }
    private void LoadCariBarang(){
         if(txtKode_barang.getText().equals("")){
                loadCariBarangDialog();
                CariDialogBarang.setTitle("Cari Barang");
            }else{
                try{
                koneksi config=new koneksi();
                config.BuatKoneksiDB();
                Statement st=config.getConnection().createStatement();
                ResultSet rs=st.executeQuery("Select * from barang where" +
                        " kode_barang='"+txtKode_barang.getText()+"'");
                if(rs.next()){
                    txtNama_barang.setText(rs.getString(2));
                    txtHarga_beli.setText(rs.getString(4));
                    txtUnit.setEnabled(true);
                    txtUnit.requestFocus();
                }else{
                    JOptionPane.showMessageDialog(this, "Kode Barang Belum Tersedia");
                    CariDialogSuplier.setVisible(false);
                    txtKode_barang.setText("");
                    txtKode_barang.requestFocus();
                }
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
    }
    private void enabledAwal(){
        txtKode_barang.setEnabled(false);
        txtUnit.setEnabled(false);
        
//       
    }
    private void initSubTotal_pembelian(){
        /*
        int HargaBeli = Integer.valueOf(txtHarga_beli.getText());
        int diskonRupiah=Integer.valueOf(txtDisc_rupiah.getText());
        int diskonPersen=Integer.valueOf(txtDisc_persen.getText());
        int unit=Integer.valueOf(txtUnit.getText());

        int DiscRupiah=HargaBeli-diskonRupiah;
        double DiscPersen=HargaBeli*(1-(0.01*diskonPersen));

        int subTotalTanpaDisc=unit*HargaBeli;
        int subTotalDiscRupiah=unit*DiscRupiah;
        double subTotalDiscPersen=unit*DiscPersen;

        String Hasil_STTD=String.valueOf(subTotalTanpaDisc);
        String Hasil_STDR=String.valueOf(subTotalDiscRupiah);
        String Hasil_STDP=String.valueOf(subTotalDiscPersen);

        try{
            if(txtDisc_rupiah.getText().equals("")){
                txtSubTotal_pembelian.setText(Hasil_STTD);
            }else if(diskonRupiah>0){
                txtSubTotal_pembelian.setText(Hasil_STDR);
            }else{
                txtSubTotal_pembelian.setText(Hasil_STDP);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
         */
         try{
                 txtSubTotal_pembelian.setText
                 (""+(Integer.parseInt(txtUnit.getText())*Integer.parseInt(txtHarga_beli.getText())));
         }catch(Exception e){
                e.printStackTrace();
         }
       
    }
    private boolean beliValid(){
        boolean b = false;

        if(txtKode_suplier.getText().trim().equals("")){
            JOptionPane.showMessageDialog(this, "Kode Suplier masih kosong !");
            b=false;
        }else if(txtKode_barang.getText().trim().equals("")){
            JOptionPane.showMessageDialog(this, "Kode Barang masih kosong !");
            b=false;
        }else if(txtUnit.getText().trim().equals("")){
            JOptionPane.showMessageDialog(this, "Unit masih kosong !");
            b=false;
        }else if(txtSubTotal_pembelian.getText().trim().equals("")){
            JOptionPane.showMessageDialog(this, "Sub Total Masih Kosong !!!\n" +
                    "silahkan arahkan kursor pada field unit dan tekan Enter !!!");
            b=false;
        }else{
            b=true;
        }
        return b;
    }
    private void tambahBeli(){
        koneksi config=new koneksi();
        config.BuatKoneksiDB();
        try{
            Statement st=config.getConnection().createStatement();
            int tambahdata=st.executeUpdate(
                    "insert into pembelian_detil  values "+
                    "(null,'"+txtId_pembelian.getText()+"','"+txtKode_barang.getText()+"','"

                    +txtUnit.getText()+"','"+txtSubTotal_pembelian.getText()+"')");

            tampilTabelBeli();
            if (tambahdata>0){
                txtKode_barang.setText("");
                txtNama_barang.setText("");
                txtUnit.setText("");
                txtHarga_beli.setText("");
                txtSubTotal_pembelian.setText("");
                txtKode_barang.requestFocus();
            }
           st.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, "Insert Data Gagal");
            e.printStackTrace();
        }

    }
    private void AksiSubBeli(){
        if(beliValid()){
            tambahBeli();
            sumTotalPembelian();
        }else{
            
        }
    }
    private void sumTotalPembelian(){
         koneksi config=new koneksi();
                config.BuatKoneksiDB();
        try{
                Statement st=config.getConnection().createStatement();
                ResultSet rs=st.executeQuery("Select SUM(sub_total) as sum_sub from pembelian_detil where" +
                        " kode_pembelian='"+txtId_pembelian.getText()+"'");
                if(rs.next()){
                    txtTotal_pembelian.setText(rs.getString(1));
                }else{
                }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private void prosesPembelian(){
        koneksi config=new koneksi();
        config.BuatKoneksiDB();
        try{
            Statement st=config.getConnection().createStatement();
            int tambahdataBeli=st.executeUpdate(
                    "insert into pembelian  values "+
                    "('"+txtId_pembelian.getText()+"',CURDATE(),'"
                    +txtKode_suplier.getText()+"','"+txtTotal_pembelian.getText()+"')");

            tableBeli.removeAll();
            if (tambahdataBeli>0){
                JOptionPane.showMessageDialog(this, "Pembelian Sukses Dilakukan !!!");
                tampilIdPembelian();
                tampilTabelBeli();
                txtKode_suplier.setText("");
                txtNama_suplier.setText("");
                txtKode_barang.setText("");
                txtNama_barang.setText("");
                txtUnit.setText("");
                txtHarga_beli.setText("");
                txtSubTotal_pembelian.setText("");
                txtTotal_pembelian.setText("");
                txtKode_suplier.requestFocus();
            }
           st.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, "Insert Data Gagal");
            e.printStackTrace();
        }

    }
    private void hapusdatabeli(int row){
        koneksi config=new koneksi();
        config.BuatKoneksiDB();
        try{
            Statement st=config.getConnection().createStatement();
            int hapusDataBeli=st.executeUpdate("delete from pembelian_detil where " +
                    "id='"+tableBeli.getValueAt(row, 0).toString()+"'");
            tampilTabelBeli();
            if (hapusDataBeli>0){
                JOptionPane.showMessageDialog(this, "Pembelian Detil telah Sukses Dihapus !");
                txtKode_barang.requestFocus();
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    private void batalBeli(){
        koneksi config=new koneksi();
        config.BuatKoneksiDB();
        try{
            Statement st=config.getConnection().createStatement();
            int batalbeli=st.executeUpdate("delete from pembelian_detil where " +
                    "kode_pembelian='"+txtId_pembelian.getText()+"'");
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public Pembelian() {
        initComponents();
        koneksi config=new koneksi();
        config.BuatKoneksiDB();
        tampilIdPembelian();
        jTextEx3.setText(""+Tanggal+"");
        txtKode_suplier.requestDefaultFocus();
        enabledAwal();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        CariDialogSuplier = new javax.swing.JDialog();
        CariDialogAtas = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        txtCari_suplier = new com.uiMIF.JTextEx();
        btnCariSuplier = new javax.swing.JButton();
        CariDialogTengah = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        CariDialogBawah = new javax.swing.JPanel();
        btnBatalCariSuplier = new javax.swing.JButton();
        btnOkCariSuplier = new javax.swing.JButton();
        CariDialogBarang = new javax.swing.JDialog();
        CariDialogAtas1 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        txtCari_Barang = new com.uiMIF.JTextEx();
        btnCari_barang_dialog = new javax.swing.JButton();
        CariDialogTengah1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        CariDialogBawah1 = new javax.swing.JPanel();
        btnBatalCariBarang = new javax.swing.JButton();
        btnOkCariBarang = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtNama_suplier = new com.uiMIF.JTextEx();
        jLabel4 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        lblKodeBarang = new javax.swing.JLabel();
        lblNamaBarang = new javax.swing.JLabel();
        lblUnit = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtKode_barang = new com.uiMIF.JTextEx();
        txtNama_barang = new com.uiMIF.JTextEx();
        txtUnit = new com.uiMIF.JTextEx();
        txtHarga_beli = new com.uiMIF.JTextEx();
        txtSubTotal_pembelian = new com.uiMIF.JTextEx();
        btnTambah_beli = new javax.swing.JButton();
        btnHapus_beli = new javax.swing.JButton();
        btnCari1 = new javax.swing.JButton();
        btnCari2 = new javax.swing.JButton();
        txtKode_suplier = new com.uiMIF.JTextEx();
        txtId_pembelian = new com.uiMIF.JTextEx();
        jTextEx3 = new com.uiMIF.JTextEx();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanel3 = new javax.swing.JPanel();
        txtTotal_pembelian = new com.uiMIF.JTextEx();
        jLabel9 = new javax.swing.JLabel();
        btnProses_pembelian = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        btnTutupBeli = new javax.swing.JButton();

        CariDialogSuplier.setAlwaysOnTop(true);
        CariDialogSuplier.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                CariDialogSuplierFocusLost(evt);
            }
        });

        jLabel10.setText("Masukkan Kata Kunci");

        btnCariSuplier.setText("Cari");
        btnCariSuplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariSuplierActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout CariDialogAtasLayout = new javax.swing.GroupLayout(CariDialogAtas);
        CariDialogAtas.setLayout(CariDialogAtasLayout);
        CariDialogAtasLayout.setHorizontalGroup(
            CariDialogAtasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CariDialogAtasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(CariDialogAtasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(CariDialogAtasLayout.createSequentialGroup()
                        .addComponent(txtCari_suplier, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCariSuplier))
                    .addComponent(jLabel10))
                .addContainerGap(133, Short.MAX_VALUE))
        );
        CariDialogAtasLayout.setVerticalGroup(
            CariDialogAtasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CariDialogAtasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(CariDialogAtasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCari_suplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCariSuplier))
                .addContainerGap())
        );

        CariDialogSuplier.getContentPane().add(CariDialogAtas, java.awt.BorderLayout.NORTH);

        CariDialogTengah.setLayout(new java.awt.BorderLayout());
        CariDialogTengah.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        CariDialogSuplier.getContentPane().add(CariDialogTengah, java.awt.BorderLayout.CENTER);

        btnBatalCariSuplier.setText("Batal");
        btnBatalCariSuplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBatalCariSuplierActionPerformed(evt);
            }
        });

        btnOkCariSuplier.setText("Ok");
        btnOkCariSuplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkCariSuplierActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout CariDialogBawahLayout = new javax.swing.GroupLayout(CariDialogBawah);
        CariDialogBawah.setLayout(CariDialogBawahLayout);
        CariDialogBawahLayout.setHorizontalGroup(
            CariDialogBawahLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, CariDialogBawahLayout.createSequentialGroup()
                .addContainerGap(278, Short.MAX_VALUE)
                .addComponent(btnOkCariSuplier)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnBatalCariSuplier)
                .addContainerGap())
        );
        CariDialogBawahLayout.setVerticalGroup(
            CariDialogBawahLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CariDialogBawahLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(CariDialogBawahLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnBatalCariSuplier)
                    .addComponent(btnOkCariSuplier))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        CariDialogSuplier.getContentPane().add(CariDialogBawah, java.awt.BorderLayout.SOUTH);

        CariDialogBarang.setAlwaysOnTop(true);
        CariDialogBarang.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                CariDialogBarangFocusLost(evt);
            }
        });

        jLabel11.setText("Masukkan Kata Kunci");

        btnCari_barang_dialog.setText("Cari");
        btnCari_barang_dialog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCari_barang_dialogActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout CariDialogAtas1Layout = new javax.swing.GroupLayout(CariDialogAtas1);
        CariDialogAtas1.setLayout(CariDialogAtas1Layout);
        CariDialogAtas1Layout.setHorizontalGroup(
            CariDialogAtas1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CariDialogAtas1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(CariDialogAtas1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(CariDialogAtas1Layout.createSequentialGroup()
                        .addComponent(txtCari_Barang, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCari_barang_dialog))
                    .addComponent(jLabel11))
                .addContainerGap(133, Short.MAX_VALUE))
        );
        CariDialogAtas1Layout.setVerticalGroup(
            CariDialogAtas1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CariDialogAtas1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(CariDialogAtas1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCari_Barang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCari_barang_dialog))
                .addContainerGap())
        );

        CariDialogBarang.getContentPane().add(CariDialogAtas1, java.awt.BorderLayout.NORTH);

        CariDialogTengah1.setLayout(new java.awt.BorderLayout());
        CariDialogTengah1.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        CariDialogBarang.getContentPane().add(CariDialogTengah1, java.awt.BorderLayout.CENTER);

        btnBatalCariBarang.setText("Batal");
        btnBatalCariBarang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBatalCariBarangActionPerformed(evt);
            }
        });

        btnOkCariBarang.setText("Ok");
        btnOkCariBarang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkCariBarangActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout CariDialogBawah1Layout = new javax.swing.GroupLayout(CariDialogBawah1);
        CariDialogBawah1.setLayout(CariDialogBawah1Layout);
        CariDialogBawah1Layout.setHorizontalGroup(
            CariDialogBawah1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, CariDialogBawah1Layout.createSequentialGroup()
                .addContainerGap(278, Short.MAX_VALUE)
                .addComponent(btnOkCariBarang)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnBatalCariBarang)
                .addContainerGap())
        );
        CariDialogBawah1Layout.setVerticalGroup(
            CariDialogBawah1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CariDialogBawah1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(CariDialogBawah1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnBatalCariBarang)
                    .addComponent(btnOkCariBarang))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        CariDialogBarang.getContentPane().add(CariDialogBawah1, java.awt.BorderLayout.SOUTH);

        setTitle("Form Pembelian");

        jLabel1.setText("Id Pembelian");

        jLabel2.setText("Kode Suplier  ");

        jLabel3.setText("Nama Suplier");

        txtNama_suplier.setEditable(false);

        jLabel4.setText("Tanggal Transaksi");

        lblKodeBarang.setText("Kode Barang");

        lblNamaBarang.setText("Nama Barang");

        lblUnit.setText("Unit");

        jLabel6.setText("Harga");

        jLabel8.setText("Total");

        txtKode_barang.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtKode_barangFocusLost(evt);
            }
        });
        txtKode_barang.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtKode_barangKeyTyped(evt);
            }
        });

        txtNama_barang.setEditable(false);

        txtUnit.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtUnit.setInputType(com.uiMIF.JTextEx.TypeText.Number);
        txtUnit.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtUnitKeyTyped(evt);
            }
        });

        txtHarga_beli.setEditable(false);

        txtSubTotal_pembelian.setEditable(false);
        txtSubTotal_pembelian.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        btnTambah_beli.setText("Tambah");
        btnTambah_beli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTambah_beliActionPerformed(evt);
            }
        });
        btnTambah_beli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                btnTambah_beliKeyTyped(evt);
            }
        });

        btnHapus_beli.setText("Hapus");
        btnHapus_beli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapus_beliActionPerformed(evt);
            }
        });

        btnCari1.setText("Cari...");
        btnCari1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCari1ActionPerformed(evt);
            }
        });

        btnCari2.setText("Cari...");
        btnCari2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCari2ActionPerformed(evt);
            }
        });

        txtKode_suplier.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtKode_suplierKeyTyped(evt);
            }
        });

        txtId_pembelian.setEnabled(false);

        jTextEx3.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(27, 27, 27)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtId_pembelian, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtKode_suplier, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(btnCari1)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(jTextEx3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(42, 42, 42)
                                .addComponent(txtNama_suplier, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 939, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtKode_barang, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCari2))
                            .addComponent(lblKodeBarang))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNama_barang, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblNamaBarang))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblUnit)
                            .addComponent(txtUnit, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(txtHarga_beli, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtSubTotal_pembelian, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnTambah_beli)
                                .addGap(6, 6, 6)
                                .addComponent(btnHapus_beli))
                            .addComponent(jLabel8))
                        .addGap(225, 225, 225)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtId_pembelian, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(btnCari1)
                            .addComponent(txtKode_suplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextEx3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtNama_suplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtSubTotal_pembelian, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnTambah_beli)
                        .addComponent(btnHapus_beli))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblUnit)
                            .addComponent(jLabel6)
                            .addComponent(lblNamaBarang)
                            .addComponent(lblKodeBarang)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNama_barang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtUnit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtHarga_beli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnCari2)
                            .addComponent(txtKode_barang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

        jPanel2.setLayout(new java.awt.BorderLayout());
        jPanel2.add(jScrollPane3, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        jLabel9.setText("Total Pembelian");

        btnProses_pembelian.setText("Proses Pembelian");
        btnProses_pembelian.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProses_pembelianActionPerformed(evt);
            }
        });

        jButton3.setText("Cetak Faktur");

        btnTutupBeli.setText("Tutup");
        btnTutupBeli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTutupBeliActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(636, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(txtTotal_pembelian, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(btnTutupBeli)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)
                        .addGap(18, 18, 18)
                        .addComponent(btnProses_pembelian)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTotal_pembelian, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnProses_pembelian)
                    .addComponent(jButton3)
                    .addComponent(btnTutupBeli))
                .addContainerGap())
        );

        getContentPane().add(jPanel3, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnTutupBeliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTutupBeliActionPerformed
        // TODO add your handling code here:
        batalBeli();
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_btnTutupBeliActionPerformed

    private void txtKode_barangKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtKode_barangKeyTyped
        // TODO add your handling code here:
        if(evt.getKeyChar()==evt.VK_ENTER){
            LoadCariBarang();
        }
    }//GEN-LAST:event_txtKode_barangKeyTyped

    private void btnOkCariSuplierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkCariSuplierActionPerformed
        // TODO add your handling code here:
        if(tableDialogSuplier.getSelectedRow()<0){
            JOptionPane.showMessageDialog(this.tableDialogSuplier, "Silahkan Pilih Suplier");
            }else{
            txtKode_suplier.setText(
            tableDialogSuplier.getValueAt(tableDialogSuplier.getSelectedRow(),0).toString());
            txtNama_suplier.setText(
            tableDialogSuplier.getValueAt(tableDialogSuplier.getSelectedRow(),1).toString());
            CariDialogSuplier.setVisible(false);
            txtKode_barang.setEnabled(true);
            txtKode_barang.requestFocus();
        }
    }//GEN-LAST:event_btnOkCariSuplierActionPerformed

    private void CariDialogSuplierFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_CariDialogSuplierFocusLost
        // TODO add your handling code here:
        
    }//GEN-LAST:event_CariDialogSuplierFocusLost

    private void btnBatalCariSuplierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBatalCariSuplierActionPerformed
        // TODO add your handling code here:
        txtCari_suplier.setText("");
        CariDialogSuplier.setVisible(false);
        txtKode_suplier.requestFocus();
    }//GEN-LAST:event_btnBatalCariSuplierActionPerformed

    private void txtKode_barangFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtKode_barangFocusLost
        // TODO add your handling code here:
       
    }//GEN-LAST:event_txtKode_barangFocusLost

    private void btnBatalCariBarangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBatalCariBarangActionPerformed
        // TODO add your handling code here:
        CariDialogBarang.setVisible(false);
    }//GEN-LAST:event_btnBatalCariBarangActionPerformed

    private void btnOkCariBarangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkCariBarangActionPerformed
        // TODO add your handling code here:
         if(tableDialogBarang.getSelectedRow()<0){
            JOptionPane.showMessageDialog(CariDialogBarang, "Silahkan Pilih Barang");
            }else{
            txtKode_barang.setText(
            tableDialogBarang.getValueAt(tableDialogBarang.getSelectedRow(),0).toString());
            txtNama_barang.setText(
            tableDialogBarang.getValueAt(tableDialogBarang.getSelectedRow(),1).toString());
            txtHarga_beli.setText(
            tableDialogBarang.getValueAt(tableDialogBarang.getSelectedRow(),3).toString());
            CariDialogBarang.setVisible(false);
            txtUnit.setEnabled(true);
            txtUnit.requestFocus();
            }
    }//GEN-LAST:event_btnOkCariBarangActionPerformed

    private void CariDialogBarangFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_CariDialogBarangFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_CariDialogBarangFocusLost

    private void btnCariSuplierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariSuplierActionPerformed
        // TODO add your handling code here:
        tampilTabelSuplierDialog();
        txtCari_suplier.setText("");
    }//GEN-LAST:event_btnCariSuplierActionPerformed

    private void btnCari_barang_dialogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCari_barang_dialogActionPerformed
        // TODO add your handling code here:
        tampilTabelBarangDialog();
        txtCari_Barang.setText("");
    }//GEN-LAST:event_btnCari_barang_dialogActionPerformed

    private void txtUnitKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtUnitKeyTyped
        // TODO add your handling code here:
        if(evt.getKeyChar()==evt.VK_ENTER){
            if(txtUnit.getText().equals("")){
                JOptionPane.showMessageDialog(this, "Jumlah Unit harus diisi !");
                txtUnit.requestFocus();
            }else if(txtUnit.getText().equals("0")){
                JOptionPane.showMessageDialog(this, "Jumlah Unit minimal 1 !");
                txtUnit.setText("");
                txtUnit.requestFocus();
            }else{
                btnTambah_beli.requestFocus();
                initSubTotal_pembelian();
            }
        }else if(evt.getKeyChar()==evt.KEY_LOCATION_NUMPAD){
            initSubTotal_pembelian();
        }
    }//GEN-LAST:event_txtUnitKeyTyped

    private void btnCari1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCari1ActionPerformed
        // TODO add your handling code here:
        loadCariSuplierDialog();
    }//GEN-LAST:event_btnCari1ActionPerformed

    private void btnCari2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCari2ActionPerformed
        // TODO add your handling code here:
        loadCariBarangDialog();
    }//GEN-LAST:event_btnCari2ActionPerformed

    private void btnTambah_beliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTambah_beliActionPerformed
        // TODO add your handling code here:
        AksiSubBeli();
    }//GEN-LAST:event_btnTambah_beliActionPerformed

    private void btnProses_pembelianActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProses_pembelianActionPerformed
        // TODO add your handling code here:
        prosesPembelian();
    }//GEN-LAST:event_btnProses_pembelianActionPerformed

    private void btnTambah_beliKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btnTambah_beliKeyTyped
        // TODO add your handling code here:
        if(evt.getKeyChar()==evt.VK_ENTER){
            AksiSubBeli();
        }
    }//GEN-LAST:event_btnTambah_beliKeyTyped

    private void btnHapus_beliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHapus_beliActionPerformed
        // TODO add your handling code here:
        try{
           if(tableBeli.getSelectedRow()<0){
               JOptionPane.showMessageDialog(this, "Silahkan pilih Data Bali yang akan dihapus !");
           }else{
              hapusdatabeli(tableBeli.getSelectedRow());
           }
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_btnHapus_beliActionPerformed

    private void txtKode_suplierKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtKode_suplierKeyTyped
        // TODO add your handling code here:
         if(evt.getKeyChar()==evt.VK_ENTER){
           LoadCariSuplier();
        }
    }//GEN-LAST:event_txtKode_suplierKeyTyped

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel CariDialogAtas;
    private javax.swing.JPanel CariDialogAtas1;
    private javax.swing.JDialog CariDialogBarang;
    private javax.swing.JPanel CariDialogBawah;
    private javax.swing.JPanel CariDialogBawah1;
    private javax.swing.JDialog CariDialogSuplier;
    private javax.swing.JPanel CariDialogTengah;
    private javax.swing.JPanel CariDialogTengah1;
    private javax.swing.JButton btnBatalCariBarang;
    private javax.swing.JButton btnBatalCariSuplier;
    private javax.swing.JButton btnCari1;
    private javax.swing.JButton btnCari2;
    private javax.swing.JButton btnCariSuplier;
    private javax.swing.JButton btnCari_barang_dialog;
    private javax.swing.JButton btnHapus_beli;
    private javax.swing.JButton btnOkCariBarang;
    private javax.swing.JButton btnOkCariSuplier;
    private javax.swing.JButton btnProses_pembelian;
    private javax.swing.JButton btnTambah_beli;
    private javax.swing.JButton btnTutupBeli;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private com.uiMIF.JTextEx jTextEx3;
    private javax.swing.JLabel lblKodeBarang;
    private javax.swing.JLabel lblNamaBarang;
    private javax.swing.JLabel lblUnit;
    private com.uiMIF.JTextEx txtCari_Barang;
    private com.uiMIF.JTextEx txtCari_suplier;
    private com.uiMIF.JTextEx txtHarga_beli;
    private com.uiMIF.JTextEx txtId_pembelian;
    private com.uiMIF.JTextEx txtKode_barang;
    private com.uiMIF.JTextEx txtKode_suplier;
    private com.uiMIF.JTextEx txtNama_barang;
    private com.uiMIF.JTextEx txtNama_suplier;
    private com.uiMIF.JTextEx txtSubTotal_pembelian;
    private com.uiMIF.JTextEx txtTotal_pembelian;
    private com.uiMIF.JTextEx txtUnit;
    // End of variables declaration//GEN-END:variables

}
